package com.monkeyboy.controller;

import com.monkeyboy.common.dto.ResData;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author Gavin
 * @date 2021.01.23 16:42
 */
@RestController
public class RestTemplateTest {
    //远程调用的 地址
    public static final String REMOTE_URL = "http://localhost:80/test?username={username}";

    @Resource
    private RestTemplate restTemplate;

    /**
     * 使用RestTemplate请求远程的接口
     * @return
     * @throws Exception
     */
    @GetMapping("/restTest")
    public ResData restTest() throws Exception {
        Map<String, Object> param = new HashMap<>();
        param.put("username", "高嘉银");
        return restTemplate.getForObject(REMOTE_URL, ResData.class, param);
    }
}
